package com.ruoyi.tb.lmt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.tb.lmt.domain.bo.McgsInfoBo;
import com.ruoyi.tb.lmt.domain.vo.McgsInfoVo;
import com.ruoyi.tb.lmt.domain.McgsInfo;
import com.ruoyi.tb.lmt.mapper.McgsInfoMapper;
import com.ruoyi.tb.lmt.service.IMcgsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 制动阀试验台_MCGSService业务层处理
 *
 * @author ruoyi
 * @date 2023-12-13
 */
@RequiredArgsConstructor
@Service
public class McgsInfoServiceImpl implements IMcgsInfoService {

    private final McgsInfoMapper baseMapper;

    /**
     * 查询制动阀试验台_MCGS
     */
    @Override
    public McgsInfoVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询制动阀试验台_MCGS列表
     */
    @Override
    public TableDataInfo<McgsInfoVo> queryPageList(McgsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<McgsInfo> lqw = buildQueryWrapper(bo);
        Page<McgsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询制动阀试验台_MCGS列表
     */
    @Override
    public List<McgsInfoVo> queryList(McgsInfoBo bo) {
        LambdaQueryWrapper<McgsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<McgsInfo> buildQueryWrapper(McgsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<McgsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getId() != null, McgsInfo::getId, bo.getId());
        lqw.eq(StringUtils.isNotBlank(bo.getDjNo()), McgsInfo::getDjNo, bo.getDjNo());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsTime()), McgsInfo::getMcgsTime, bo.getMcgsTime());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJxbh()), McgsInfo::getMcgsJxbh, bo.getMcgsJxbh());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsCzz()), McgsInfo::getMcgsCzz, bo.getMcgsCzz());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsZsch()), McgsInfo::getMcgsZsch, bo.getMcgsZsch());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsQj11()), McgsInfo::getMcgsQj11, bo.getMcgsQj11());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsQj12()), McgsInfo::getMcgsQj12, bo.getMcgsQj12());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsQj13()), McgsInfo::getMcgsQj13, bo.getMcgsQj13());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsQj14()), McgsInfo::getMcgsQj14, bo.getMcgsQj14());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsQj15()), McgsInfo::getMcgsQj15, bo.getMcgsQj15());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsSch()), McgsInfo::getMcgsSch, bo.getMcgsSch());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsBy1()), McgsInfo::getMcgsBy1, bo.getMcgsBy1());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFh()), McgsInfo::getMcgsFh, bo.getMcgsFh());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf1()), McgsInfo::getMcgsFpf1, bo.getMcgsFpf1());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf2()), McgsInfo::getMcgsFpf2, bo.getMcgsFpf2());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf3()), McgsInfo::getMcgsFpf3, bo.getMcgsFpf3());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf4()), McgsInfo::getMcgsFpf4, bo.getMcgsFpf4());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf5()), McgsInfo::getMcgsFpf5, bo.getMcgsFpf5());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf6()), McgsInfo::getMcgsFpf6, bo.getMcgsFpf6());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf7()), McgsInfo::getMcgsFpf7, bo.getMcgsFpf7());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf8()), McgsInfo::getMcgsFpf8, bo.getMcgsFpf8());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf9()), McgsInfo::getMcgsFpf9, bo.getMcgsFpf9());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf10()), McgsInfo::getMcgsFpf10, bo.getMcgsFpf10());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf11()), McgsInfo::getMcgsFpf11, bo.getMcgsFpf11());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf12()), McgsInfo::getMcgsFpf12, bo.getMcgsFpf12());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf13()), McgsInfo::getMcgsFpf13, bo.getMcgsFpf13());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf14()), McgsInfo::getMcgsFpf14, bo.getMcgsFpf14());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf15()), McgsInfo::getMcgsFpf15, bo.getMcgsFpf15());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf16()), McgsInfo::getMcgsFpf16, bo.getMcgsFpf16());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf17()), McgsInfo::getMcgsFpf17, bo.getMcgsFpf17());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf18()), McgsInfo::getMcgsFpf18, bo.getMcgsFpf18());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf19()), McgsInfo::getMcgsFpf19, bo.getMcgsFpf19());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf20()), McgsInfo::getMcgsFpf20, bo.getMcgsFpf20());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsFpf21()), McgsInfo::getMcgsFpf21, bo.getMcgsFpf21());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsKzc()), McgsInfo::getMcgsKzc, bo.getMcgsKzc());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz1()), McgsInfo::getMcgsXz1, bo.getMcgsXz1());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz2()), McgsInfo::getMcgsXz2, bo.getMcgsXz2());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz3()), McgsInfo::getMcgsXz3, bo.getMcgsXz3());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz4()), McgsInfo::getMcgsXz4, bo.getMcgsXz4());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz5()), McgsInfo::getMcgsXz5, bo.getMcgsXz5());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz6()), McgsInfo::getMcgsXz6, bo.getMcgsXz6());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz7()), McgsInfo::getMcgsXz7, bo.getMcgsXz7());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz8()), McgsInfo::getMcgsXz8, bo.getMcgsXz8());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz9()), McgsInfo::getMcgsXz9, bo.getMcgsXz9());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz10()), McgsInfo::getMcgsXz10, bo.getMcgsXz10());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz11()), McgsInfo::getMcgsXz11, bo.getMcgsXz11());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz12()), McgsInfo::getMcgsXz12, bo.getMcgsXz12());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz13()), McgsInfo::getMcgsXz13, bo.getMcgsXz13());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz14()), McgsInfo::getMcgsXz14, bo.getMcgsXz14());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz15()), McgsInfo::getMcgsXz15, bo.getMcgsXz15());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz16()), McgsInfo::getMcgsXz16, bo.getMcgsXz16());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz17()), McgsInfo::getMcgsXz17, bo.getMcgsXz17());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz18()), McgsInfo::getMcgsXz18, bo.getMcgsXz18());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz19()), McgsInfo::getMcgsXz19, bo.getMcgsXz19());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXljc()), McgsInfo::getMcgsXljc, bo.getMcgsXljc());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsXz20()), McgsInfo::getMcgsXz20, bo.getMcgsXz20());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJhb109e1()), McgsInfo::getMcgsJhb109e1, bo.getMcgsJhb109e1());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJhb109e2()), McgsInfo::getMcgsJhb109e2, bo.getMcgsJhb109e2());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJhb109e3()), McgsInfo::getMcgsJhb109e3, bo.getMcgsJhb109e3());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJhb109e4()), McgsInfo::getMcgsJhb109e4, bo.getMcgsJhb109e4());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJhb109e5()), McgsInfo::getMcgsJhb109e5, bo.getMcgsJhb109e5());
        lqw.eq(StringUtils.isNotBlank(bo.getMcgsJhb109e6()), McgsInfo::getMcgsJhb109e6, bo.getMcgsJhb109e6());
        lqw.eq(StringUtils.isNotBlank(bo.getDelFlag()), McgsInfo::getDelFlag, bo.getDelFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), McgsInfo::getCreateBy, bo.getCreateBy());
        lqw.eq(bo.getCreateTime() != null, McgsInfo::getCreateTime, bo.getCreateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getUpdateBy()), McgsInfo::getUpdateBy, bo.getUpdateBy());
        lqw.eq(bo.getUpdateTime() != null, McgsInfo::getUpdateTime, bo.getUpdateTime());
        return lqw;
    }

    /**
     * 新增制动阀试验台_MCGS
     */
    @Override
    public Boolean insertByBo(McgsInfoBo bo) {
        McgsInfo add = BeanUtil.toBean(bo, McgsInfo.class);
        add.setDelFlag("0");
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改制动阀试验台_MCGS
     */
    @Override
    public Boolean updateByBo(McgsInfoBo bo) {
        McgsInfo update = BeanUtil.toBean(bo, McgsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(McgsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除制动阀试验台_MCGS
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public String getMaxMcgsTime(){
        return baseMapper.getMaxMcgsTime();
    }
}
